00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _DETHREADPOOL_HPP
00029 #define _DETHREADPOOL_HPP
00030
00031 #ifndef _DENET_HPP
00032 #include "deNet.hpp"
00033 #endif
00034
00035 #ifndef _DETHREAD_HPP
00036 #include "deThread.hpp"
00037 #endif
00038
00039 #ifndef _DESYNCHOBJECT_HPP
00040 #include "deSynchObject.hpp"
00041 #endif
00042
00043 #include <VECTOR>
00044 #include <STACK>
00045 #include <QUEUE>
00046
00047 class DENET_API deThreadPool
00048 {
00049 public:
00050
00051 deThreadPool(void);
00052 virtual ~deThreadPool(void);
00053
00054 bool CreateThreads( int iNum );
00055 deThread * ActivateIdleThread( deThread::ActiveProcess process, void * param, DWORD paramSize, DWORD dwDesc = NULL, bool bCreateThread = false );
00056 int ActivateQueuedJobs( int iNumCreatedThreads = 0 );
00057 bool DestroyAllThreads( bool bForceKill = false );
00058
00059 DWORD GetNumActiveThreads(void);
00060 DWORD GetNumIdleThreads(void);
00061
00062
00063 bool NotifyOnIdle( deThread * pThread );
00064
00065 static deThreadPool * GetMgr(void) { return m_Singleton; }
00066
00067 protected:
00068
00069 class JobDesc
00070 {
00071 public:
00072
00073 JobDesc(void) : m_pProcessData(NULL) { }
00074 ~JobDesc(void) { SAFE_DELETE_ARRAY(m_pProcessData); }
00075
00076 enum Flags
00077 {
00078 JOB_KILL_THREAD_ON_COMPLETION = 0x0001,
00079 };
00080
00081 deThread * m_pThread;
00082 deThread::ActiveProcess m_pProcess;
00083 BYTE * m_pProcessData;
00084 DWORD m_dwDesc;
00085 };
00086
00087 typedef std::stack<deThread*> stackThreads;
00088 typedef std::vector<JobDesc*> aJobs;
00089 typedef std::queue<JobDesc*> queueJobs;
00090
00091 queueJobs m_queWaitingJobs;
00092 stackThreads m_stkIdleThreads;
00093 aJobs m_aActiveJobs;
00094 deSynchObject m_SynchObject;
00095
00096 static deThreadPool * m_Singleton;
00097 };
00098
00099 #endif